﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Demonstartor
{
    class RusParamsReader
    {
        Dictionary<string, string> XmlNameShortName;
        Dictionary<string, string> ShortNameFullName;

        public RusParamsReader()
        {
            XmlNameShortName = new Dictionary<string, string>();
            ShortNameFullName = new Dictionary<string, string>();

            CSVFileReader B3Config = new CSVFileReader("B3Config.txt", ' ');

            string[] Cur;

            while ((Cur = B3Config.Read()) != null)
            {
                if (Cur.Count() != 2)
                    throw new Exception("Wrong B3 config file");

                XmlNameShortName.Add(Cur[1], Cur[0]);
            }

            B3Config.Close();

            CSVFileReader ParamsTu204 = new CSVFileReader("ParamsTu204.txt", '\t');

            while ((Cur = ParamsTu204.Read()) != null)
            {
                if (Cur.Count() < 2)
                    throw new Exception("Wrong ParamsTu204 config file");

                if (!ShortNameFullName.ContainsKey(Cur[0]))
                    ShortNameFullName.Add(Cur[0], Cur[1]);
            }

            ParamsTu204.Close();
        }

        public bool Resolve(string Name, out string ShortName, out string FullName)
        {


            if (!XmlNameShortName.ContainsKey(Name))
            {
                ShortName = Name;
                FullName = Name;
                return false;
            }
            else
                ShortName = XmlNameShortName[Name];


            if (!ShortNameFullName.ContainsKey(ShortName))
            {
                FullName = ShortName;
                return false;
            }
            else
                FullName = ShortNameFullName[ShortName];

            return true;
        }
    }

}
